#include <queue>
#include "GlobeControl.h"
#include "Recognizer.h"

DWORD WINAPI startMessageHandleThread (LPVOID lpParam);
DWORD WINAPI startSpeechRecognizerThread (LPVOID lpParam);

using namespace std;

queue< Ptr< Message > > messageQueue;


int main(int argc, char** argv){
  glutInit (&argc, argv);

  glenv_create_window (GLUT_RGBA | GLUT_DOUBLE, "Virtual Globe", false, 1024, 1024);

  GlControl* control = new GlobeControl ();
  Recognizer* recognizer = new Recognizer ();

  HANDLE messageHandleThread = CreateThread (NULL, 0,
    startMessageHandleThread, (LPVOID)control, 0, NULL);
  HANDLE speechRecognizerThread = CreateThread (NULL, 0,
    startSpeechRecognizerThread, (LPVOID)recognizer, 0, NULL);

  glenv_run (control);

	//VGlobeApp vga;
	//ts.add_listener((EventListener *) &vga);
	//ts.start_process();
	//vga.start();

	system("pause");
}

DWORD WINAPI startMessageHandleThread (LPVOID lpParam)
{
  GlobeControl* control = (GlobeControl*)lpParam;
  while (1)
  {
    control->handleMessage ();
  }
  return 0;
}

DWORD WINAPI startSpeechRecognizerThread (LPVOID lpParam)
{
  Recognizer* recognizer = (Recognizer*)lpParam;
  recognizer->startRec ();
  return 0;
}
